package com.learn.security.core.validate.code;

import com.learn.security.core.properties.SecurityProperties;
import com.learn.security.core.validate.code.image.ImageValidateCodeGenerator;
import com.learn.security.core.validate.code.sms.DefaultSmsCodeSender;
import com.learn.security.core.validate.code.sms.SmsCodeSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 定义生效的---验证码的生成接口的实现类
 */
@Configuration
public class ValidateCodeBeanConfig {

    @Autowired
    SecurityProperties securityProperties;

    /**
     * 定义默认生效的---验证码的生成接口的实现类
     */
    @Bean
    @ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
    public ValidateCodeGenerator imageValidateCodeGenerator(){
        ImageValidateCodeGenerator codeGenerator = new ImageValidateCodeGenerator();
        codeGenerator.setSecurityProperties(securityProperties);
        return  codeGenerator;
    }

    /**
     * 定义默认生效的---短信验证码的发射接口的实现类
     */
    @Bean
    @ConditionalOnMissingBean(SmsCodeSender.class)
    public SmsCodeSender smsCodeSender(){
        return  new DefaultSmsCodeSender();
    }
}
